package gncom.qr;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainPage extends Activity implements OnClickListener {

	private static Vibrator vibe;
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main_page);
		
		
		

		Button goto25qrPageBtn = (Button) findViewById(R.id.goto25qrPageBtn);
		Button gotoStoryPageBtn = (Button) findViewById(R.id.gotoStoryPageBtn);
		Button gotoServicePageBtn = (Button) findViewById(R.id.gotoServicePageBtn);
		Button gotoInfoPageBtn = (Button) findViewById(R.id.gotoInfoPageBtn);

		goto25qrPageBtn.setOnClickListener(this);
		gotoStoryPageBtn.setOnClickListener(this);
		gotoServicePageBtn.setOnClickListener(this);
		gotoInfoPageBtn.setOnClickListener(this);

		vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

	}// end onCreate()

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			AlertDialog.Builder alert = new AlertDialog.Builder(this);
			alert.setTitle("종료하시겠습니까?");
			alert.setPositiveButton("확 인", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					finish();
				}
			});
			alert.show();
			return false;
		}
		
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.goto25qrPageBtn:
			intent = new Intent(getApplicationContext(), CaptureActivity.class);
			finish();
			break;
		case R.id.gotoStoryPageBtn:
			intent = new Intent(this, StoryPage.class);
			break;
		case R.id.gotoServicePageBtn:
		
			// Toast.makeText(this, "서비스 준비중입니다.", Toast.LENGTH_LONG).show();
			intent = new Intent(getApplicationContext(), ServicePage.class);
			break;
		case R.id.gotoInfoPageBtn:
			intent = new Intent(getApplicationContext(), InfoPage.class);
			break;
		}
		
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		startActivity(intent);
		vibe.vibrate(50);
	}
}